﻿using AuthCenter.Domain;
using AuthCenter.ErorCode;
using AuthCenter.Infrastructure;
using AuthCenter_API.Read.Applications.Commands.RBAC;
using MediatR;

namespace AuthCenter_API.Read.Applications.CommandHandlers.RBAC
{
    public class DepQueryCommandHandler : IRequestHandler<DepQueryCommand, APIResult<List<UserModel>>>
    {
        private readonly IBaseRepository<UserModel> _userRepository;

        public DepQueryCommandHandler(IBaseRepository<UserModel> userRepository)
        {
            _userRepository = userRepository;
        }

        public Task<APIResult<List<UserModel>>> Handle(DepQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<UserModel>> result = new APIResult<List<UserModel>>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _userRepository.GetAll().Where(x => x.DepId == request.DepId);
            result.Data = m.ToList();
            return Task.FromResult(result);
        }
    }
}
